﻿using System.IO;
using System.Xml.Linq;

namespace SlamCms.Configuration
{
	public class SolutionConfiguration : Configuration, IConfigurationSettings
	{	
		private ConfigurationSettingDictionary _settings;

		public SolutionConfiguration()
		{
			string solutionConfigPath = Path.Combine(ConfigurationManager.ConfigurationFolderPath, "Solution.config");
			if (!File.Exists(solutionConfigPath))
			{
				throw new FileNotFoundException("Solution.config not found. SLAM CMS Configuration expects the Solution.config for this application to exist at " + solutionConfigPath);
			}

			Load(XDocument.Load(solutionConfigPath));

			ConfigurationHelpers.LoadProperties(this);
		}

		public ConfigurationSettingDictionary Settings
		{
			get
			{	
				return _settings;
			}
		}

		protected override void Load(XDocument configurationXml)
		{
			base.Load(configurationXml);
			_settings = new ConfigurationSettingDictionary(this);
		}
	}
}
